import { authService } from "../../service/authService";
import { userService } from "../../service/userService";

const plugin = (store) => {
  // 当 store 初始化后调用
  store.subscribe((mutation) => {
    // 每次 mutation 之后调用
    // mutation 的格式为 { type, payload }
    if (mutation.type === "user/updateToken") {
      authService.setToken(mutation.payload);
    } else if (mutation.type === "user/updateUserInfo") {
      userService.setUserInfo(mutation.payload);
    }
  });
};

export { plugin };
